<?php
	require_once APP.'vendors'.DS.'os_player'.DS.'flash.php';
	class OsPlayerHelper extends AppHelper
	{
		var $helpers = array('Html','Javascript');
		//autoload is neccesary as this not work properly with autoplay is off
		function flvstring($movieUrl,$moviePath, $configOptions = array()){
			$defaults = array("previewImage"=>null,'width'=>-1,'height'=>-1,'fgcolor'=>"",'bgcolor'=>"",'autoplay'=>false,'autoload'=>false,'autorewind'=>true,'volume'=>70,'loop'=>false,'mute'=>false,'muteonly'=>false,'clickurl'=>"",'clicktarget'=>"");
            $configOptions = am($defaults,$configOptions);
            extract($configOptions);
            if(!file_exists($moviePath))
			{
				return false;
			}
			$jsFile = $this->Html->url('/js/'.getFlvJSFile());
			$jsTag = "<script type='text/javascript' charset='ISO-8859-1' src='$jsFile'></script>";
			$this->getView()->addScript("flv_player_js_file",$jsTag);
			if($width == -1 || $height == -1)
			list($width, $height) = getflvsize($moviePath);

			$height += 40;
			$retval = '';
			$options = array();

			if($fgcolor && $accentcolor !== '' && $accentcolor !== 'default')
			$options[] = "accentcolor=$accentcolor";
			if($bgcolor && $btncolor !== '' && $btncolor !== 'default')
			$options[] = "btncolor=$btncolor";

			if($autoplay == false || $autoplay === 'default')
			$options[] = 'autoplay=off';
				
			if($autoload)
                $options[] = 'autoload=on';
				
			if($volume && $volume !== '' && $volume !== 'default')
			$options[] = "volume=$volume";
			if($mute && $mute !== '' && $mute !== 'default')
			$options[] = 'mute=off';
			$imgFile = preg_replace('/\.flv$/','.jpg',$movieUrl);
            if($previewImage)
			{
              $options[] = 'previewimage='.$previewImage;
            }
            $options = implode('&', $options);
			if(strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE'))
			$retval = "<!-- saved from url=(0013)about:internet -->\n";
			$playerUrl = $this->Html->url("/swf/OSplayer");
			$retval .= "<script language='javascript'>\n";
			$retval .= "  var src = '$playerUrl';\n";
			$retval .= "  if(!DetectFlashVer(9, 0, 0) && DetectFlashVer(8, 0, 0))\n";
			$retval .= "   src = '$playerUrl';\n";
			$retval .= "  AC_FL_RunContent('codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0', 'width', $width, 'height', $height, 'src', src, 'pluginspage', 'http://www.macromedia.com/go/getflashplayer',	'id', 'flvPlayer', 'allowFullScreen', 'true', 'movie', src, 'FlashVars','movie=$movieUrl&$options');\n";
			$retval .= "</script>\n";
			$retval .= "<noscript>\n";
			$retval .= "<object width='$width' height='$height' id='flvPlayer'>\n";
			$retval .= " <param name='allowFullScreen' value='true'>\n";
			$retval .= " <param name='movie' value='$playerUrl?movie=$movieUrl&$options'>\n";
			$retval .= " <embed src='$playerUrl.swf?movie=$movieUrl&$options' width='$width' height='$height' allowFullScreen='true' type='application/x-shockwave-flash'>\n";
			$retval .= "</object>\n";
			$retval .= "</noscript>\n";
			
			return	 $retval;
		}
	}
?>